﻿using PMS.Core.Infrastructure;
using Quartz;
using Quartz.Spi;
using System;

namespace PMS.Services.Utils.ScheduleTasks
{
    /// <summary>
    /// https://github.com/quartznet/quartznet/issues/65
    /// 为什么要实现使用JobFactory
    /// </summary>
    public class IOCJobFactory : IJobFactory
    {
        //private readonly IServiceProvider _serviceProvider;
        public IOCJobFactory()
        {
            //_serviceProvider = serviceProvider;
        }
        public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
        {
            //return _serviceProvider.GetService(bundle.JobDetail.JobType) as IJob;
            return EngineContext.Current.Resolve(bundle.JobDetail.JobType) as IJob;
        }

        public void ReturnJob(IJob job)
        {
            (job as IDisposable)?.Dispose();
        }
    }

}
